import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;

/**
 * @author by zyl
 * @date 2020/3/28.
 */
public class Base64 {

    public static String encode(String str){
        String base64Str="";
        try{
            byte[] data=str.getBytes("utf-8");
            base64Str= DatatypeConverter.printBase64Binary(data);
        }catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return base64Str;
    }

    public static String decode(String base64Str){
        String str="";
        byte[] base64Data=DatatypeConverter.parseBase64Binary(base64Str);
        try{
            str=new String(base64Data,"utf-8");
        }catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return str;
    }

}